package com.yang.controller.admin;

import com.yang.bean.MarketGoods;
import com.yang.bean.common.BasePageInfo;
import com.yang.bean.common.BaseRespVo;
import com.yang.bean.common.CommonData;
import com.yang.bean.zdd.bo.CreateBo;
import com.yang.bean.zdd.vo.CatAndBrandVo;
import com.yang.bean.zdd.vo.DetailVo;
import com.yang.service.admin.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName AdminGoodsController
 * @Description TODO 商品管理模块controller
 * @Author zhangdongdong
 * @Date 2022/9/7 20:03
 * @Version 1.0
 */
@RestController
@RequestMapping("admin/goods")
@Validated
public class AdminGoodsController {
    @Autowired
    GoodsService goodsService;

    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo basePageInfo, String goodsId, String goodsSn, String name) {
        CommonData<MarketGoods> data = goodsService.list(basePageInfo, goodsId, goodsSn, name);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("catAndBrand")
    public BaseRespVo catAndBrand() {
        CatAndBrandVo data = goodsService.catAndBrand();
        return BaseRespVo.ok(data);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody @Validated CreateBo createBo) {
        goodsService.create(createBo);
        return BaseRespVo.ok();
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        DetailVo data = goodsService.detail(id);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody CreateBo updateBo) {
        goodsService.update(updateBo);
        return BaseRespVo.ok();
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketGoods goods) {
        goodsService.delete(goods);
        return BaseRespVo.ok();
    }
}
